home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / gkismet / BoomBox.pm < prev    next >
Text File  |  2005-10-20  |  5KB  |  158 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # $Id: BoomBox.pm,v 1.5 2003/07/23 04:23:39 solovam Exp $
  4. #
  5. # This file is a part of gkismet
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20. #
  21.  
  22. #
  23. # BoomBox class
  24. #
  25. package BoomBox;
  26.  
  27. use Misc;
  28. use ReusableConnObserver;
  29. use strict;
  30. @BoomBox::ISA = qw(ReusableConnObserver);
  31.  
  32. my $timeout = 3;
  33.  
  34. sub new
  35. {
  36.     my $type = shift;
  37.     my $self = new ReusableConnObserver(@_);
  38.     bless $self, $type;
  39.  
  40.     $self->{'nNetworks'} = 0;
  41.     $self->{'gpsLock'} = 0;
  42.     $self->{'packets'} = 0;
  43.     $self->{'dropped'} = 0;
  44.     $self->{'lastNetworkSound'} = 0;
  45.     $self->{'lastGpsSound'} = 0;
  46.     $self->{'lastTrafficSound'} = 0;
  47.     $self->{'lastAlertSound'} = 0;
  48.  
  49.     return $self;
  50. }
  51.  
  52. sub flush
  53. {
  54.     my $self = shift;
  55.  
  56.     $self->{'nNetworks'} = 0;
  57.     $self->{'gpsLock'} = 0;
  58.     $self->{'packets'} = 0;
  59.     $self->{'dropped'} = 0;
  60.     $self->{'lastNetworkSound'} = 0;
  61.     $self->{'lastGpsSound'} = 0;
  62.     $self->{'lastTrafficSound'} = 0;
  63.     $self->{'lastAlertSound'} = 0;
  64. }
  65.  
  66. sub update
  67. {
  68.     my $self = shift;
  69.     my $object = shift;
  70.     my $data = shift;
  71.  
  72.     if($object->isa('Connection') && defined $self->{'connection'} && $self->{'connection'} eq $object)
  73.     {
  74.         if($data->{'changed'} eq 'network')
  75.         {
  76.             my @networks = keys %{$self->{'connection'}->{'network'}};
  77.             my $newNNetworks = $#networks + 1;
  78.             if($newNNetworks > $self->{'nNetworks'})
  79.             {
  80.                 if(time() - $self->{'lastNetworkSound'} > $timeout &&
  81.                     $self->{'gKismetApplication'}->{'preferences'}->getPref('networkSoundEnabled'))
  82.                 {
  83.                     $self->play($self->{'gKismetApplication'}->{'preferences'}->getPref('newNetworkSound'));
  84.                     $self->{'lastNetworkSound'} = time();
  85.                 }
  86.             }
  87.             $self->{'nNetworks'} = $newNNetworks;
  88.         }
  89.  
  90.         if($data->{'changed'} eq 'gps' && defined $self->{'connection'}->{'gps'}->{'fix'})
  91.         {
  92.             my $newGpsLock = $self->{'connection'}->{'gps'}->{'fix'};
  93.             if(time() - $self->{'lastGpsSound'} > $timeout &&
  94.                 $self->{'gKismetApplication'}->{'preferences'}->getPref('gpsSoundEnabled'))
  95.             {
  96.                 if($newGpsLock  >= 2 && $self->{'gpsLock'} < 2)
  97.                 {
  98.                     $self->play($self->{'gKismetApplication'}->{'preferences'}->getPref('gpsAcqSound'));
  99.                     $self->{'lastGpsSound'} = time();
  100.                 }
  101.                 elsif($newGpsLock  < 2 && $self->{'gpsLock'} >= 2)
  102.                 {
  103.                     $self->play($self->{'gKismetApplication'}->{'preferences'}->getPref('gpsLostSound'));
  104.                     $self->{'lastGpsSound'} = time();
  105.                 }
  106.             }
  107.             $self->{'gpsLock'} = $newGpsLock;
  108.         }
  109.  
  110.         if($data->{'changed'} eq 'info' && defined $self->{'connection'}->{'info'}->{'packets'} && defined $self->{'connection'}->{'info'}->{'dropped'})
  111.         {
  112.             my $newPackets = $self->{'connection'}->{'info'}->{'packets'};
  113.             my $newDropped = $self->{'connection'}->{'info'}->{'dropped'};
  114.             if(time() - $self->{'lastTrafficSound'} > $timeout &&
  115.                 $self->{'gKismetApplication'}->{'preferences'}->getPref('trafficSoundEnabled'))
  116.             {
  117.                 my $deltaPackets = $newPackets - $self->{'packets'};
  118.                 my $deltaDropped = $newDropped - $self->{'dropped'};
  119.                 if($deltaPackets > 0)
  120.                 {
  121.                     if($deltaPackets > $deltaDropped)
  122.                     {
  123.                         $self->play($self->{'gKismetApplication'}->{'preferences'}->getPref('trafficSound'));
  124.                         $self->{'lastTrafficSound'} = time();
  125.                     }
  126.                     else
  127.                     {
  128.                         $self->play($self->{'gKismetApplication'}->{'preferences'}->getPref('junkTrafficSound'));
  129.                         $self->{'lastTrafficSound'} = time();
  130.                     }
  131.                 }
  132.             }
  133.             $self->{'packets'} = $newPackets;
  134.             $self->{'dropped'} = $newDropped;
  135.         }
  136.  
  137.         if($data->{'changed'} eq 'alert')
  138.         {
  139.             if(time() - $self->{'lastAlertSound'} > $timeout &&
  140.                 $self->{'gKismetApplication'}->{'preferences'}->getPref('alertSoundEnabled'))
  141.             {
  142.                 $self->play($self->{'gKismetApplication'}->{'preferences'}->getPref('alertSound'));
  143.                 $self->{'lastAlertSound'} = time();
  144.             }
  145.         }
  146.         }
  147. }
  148.  
  149. sub play
  150. {
  151.     my $self = shift;
  152.     my $sound = shift;
  153.     my $playBinary = $self->{'gKismetApplication'}->{'preferences'}->getPref('playBinary');
  154.     system("$playBinary $sound >/dev/null 2>&1 &");
  155. }
  156.  
  157. 1;
  158.